home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / prgtools / euphor13.zip / SANITY.EX < prev    next >
Text File  |  1995-05-16  |  19KB  |  927 lines

  1.         ------------------------------------------
  2.         -- AUTOMATIC SELF-CHECKING SANITY TEST  --
  3.         -- for Euphoria                         --
  4.         -- A quick test of most of the features --
  5.         ------------------------------------------
  6. with type_check
  7. with trace
  8. include get.e
  9. include graphics.e
  10. include sort.e
  11. include machine.e
  12. include file.e
  13. include wildcard.e
  14. include image.e
  15.  
  16. trace(0)
  17.  
  18. constant msg = 1 -- place to send messages
  19.  
  20. global object y, i, r
  21.  
  22. procedure the_end()
  23.     if atom(gets(0)) then
  24.     end if
  25.     if graphics_mode(-1) then
  26.     end if
  27.     abort(1)
  28. end procedure
  29.  
  30. procedure make_sound()
  31. -- test sound() built-in
  32.     for i = 500 to 5000 by 500 do
  33.     sound(i)
  34.     for j = 1 to 100000 do
  35.     end for
  36.     sound(0)
  37.     end for
  38. end procedure
  39.  
  40. without warning
  41. procedure abort()
  42. -- force abort with trace back
  43.     puts(msg, "\ndivide by 0 to get trace back...Press Enter\n")
  44.     if sequence(gets(0)) then
  45.     end if
  46.     ? 1/0
  47. end procedure
  48. with warning
  49.  
  50. procedure show(object x, object y)
  51. -- show the mismatched values
  52.     puts(msg, "\n   ---MISMATCH--- \n   x is ")
  53.     ? x
  54.     puts(msg, "   y is ")
  55.     ? y
  56.     abort()
  57. end procedure
  58.  
  59. constant epsilon = 1e-10 -- allow for small floating point inaccuracy
  60.  
  61. procedure same(object x, object y)
  62. -- object x must be identical to object y else abort program
  63.     atom ratio
  64.  
  65.     if atom(x) and atom(y) then
  66.     if x = y then
  67.         return
  68.     else
  69.         if y = 0 then
  70.         show(x, y)
  71.         else
  72.         ratio = x / y
  73.         if ratio < 1 - epsilon or ratio > 1 + epsilon then
  74.             show(x, y)
  75.         end if
  76.         end if
  77.     end if
  78.     elsif length(x) = length(y) then
  79.     for i = 1 to length(x) do
  80.         same(x[i], y[i])
  81.     end for
  82.     else
  83.     show(x, y)
  84.     end if
  85. end procedure
  86.  
  87. function abs(atom x)
  88. -- absolute value
  89.     if x < 0 then
  90.     return -x
  91.     else
  92.     return x
  93.     end if
  94. end function
  95.  
  96. function built_in()
  97. -- built-in tests
  98.     sequence d
  99.  
  100.     d = date()
  101.     if d[1] < 93 or d[2] > 12 or d[3] < 1 or d[4] > 23 or d[5] > 59 or
  102.     d[6] >59 or d[7] > 7  or d[8] > 366 then
  103.     abort()
  104.     end if
  105.     d = power({-5, -4.5, -1,  0, 1,  2,  3.5, 4, 6},
  106.           { 3,    2, -1,0.5, 0, 29, -2.5, 5, 8})
  107.     if d[1] != -125 or d[2] != 20.25 or d[3] != -1 or d[4] != 0 then
  108.     abort()
  109.     end if 
  110.     if d[5] != 1 or d[6] != 536870912 or d[7] <.043 or d[7] > .044 then
  111.     abort()
  112.     end if
  113.     if d[8] != 1024 or d[9] != 1679616 or power(2,3) != 8 then
  114.     abort()
  115.     end if
  116.     same(power(16, 0.5), 4)
  117.     d = remainder({5, 9, 15, -27}, {3, 4, 5, 6})
  118.     if d[1] != 2 or d[2] != 1 or d[3] != 0 or d[4] != -3 then
  119.     abort()
  120.     end if
  121.     d = remainder({11.5, -8.8, 3.5, 5.0}, {2, 3.5, -1.5, -100.0})
  122.     if d[1] != 1.5 or d[2] < -1.81 or d[2] > -1.79 or d[3] != 0.5 or d[4] != 5 then
  123.     abort()
  124.     end if
  125.     same(4, sqrt(16))
  126.     same(3, length("ABC"))
  127.     same({1, 1, 1, 1}, repeat(1, 4))
  128.     if rand(10) > 10 or rand(20) < 1 or not find(rand(5.5), {1,2,3,4,5}) then
  129.     abort()
  130.     end if
  131.     if time() < 0 then
  132.     abort()
  133.     end if
  134.     if abs(sin(3.1415)) > 0.02 then
  135.     abort()
  136.     end if
  137.     if cos(0) < .98 then
  138.     abort()
  139.     end if
  140.     if abs(tan(3.14/4) - 1) > .02 then
  141.     abort()
  142.     end if
  143.     if log(2.7) < 0.8 or log(2.7) > 1.2 then
  144.     abort()
  145.     end if
  146.     if floor(-3.3) != -4 then
  147.     abort()
  148.     end if
  149.     if floor(-999/3.000000001) != -333 then
  150.     abort()
  151.     end if
  152.     if floor(9.99/1) != 9 then
  153.     abort()
  154.     end if
  155.     for i = -9 to 2 do
  156.     if i = 1 then
  157.         return i
  158.     end if
  159.     end for
  160. end function
  161.  
  162. procedure sub()
  163.     y = 200
  164. end procedure
  165.  
  166. procedure overflow()
  167. -- test overflows from integer into floating point
  168.     object two29, two30, maxint, prev_i
  169.     integer two30i, mtwo30i
  170.     sequence s
  171.  
  172.     two30 = 1
  173.     for i = 1 to 30 do
  174.     two30 = two30 * 2
  175.     end for
  176.     s = {two30, two30+1, two30+2}
  177.     s = s + s
  178.     if compare(s, {two30*2, two30*2+2, two30*2+4}) then
  179.     abort()
  180.     end if
  181.     mtwo30i = -1
  182.     for i = 1 to 29 do
  183.     mtwo30i = mtwo30i * 2
  184.     end for
  185.     two30i = 1
  186.     for i = 1 to 29 do
  187.     two30i = two30i * 2
  188.     end for
  189.     if 2 * two30i != -2 * mtwo30i then
  190.     abort()
  191.     end if
  192.     if two30i*2 != two30 then
  193.     abort()
  194.     end if
  195.     two29 = floor(two30 / 2)
  196.     if two29 + two29 != two30 then
  197.        abort()
  198.     end if
  199.  
  200.     maxint = floor(two30 - 1)
  201.     if maxint + 1 != two30 then
  202.     abort()
  203.     end if
  204.  
  205.     if 2 + maxint != two30 + 1 then
  206.     abort()
  207.     end if
  208.  
  209.     if (-maxint - 1) * -1 != two30 then
  210.     abort()
  211.     end if
  212.  
  213.     prev_i = -maxint + 1
  214.     for i = -maxint to -maxint -5 by -1 do
  215.     if i != prev_i - 1 then
  216.         abort()
  217.     end if
  218.     prev_i = i
  219.     end for
  220.  
  221.     prev_i = maxint - 5
  222.     for i = maxint - 3 to maxint + 3 by 2 do
  223.     if i != prev_i + 2 then
  224.         abort()
  225.     end if
  226.     prev_i = i
  227.     end for
  228.  
  229.     if floor(two30) != two30 then
  230.     abort()
  231.     end if
  232.  
  233.     if floor(two30 + two30 - 1) != two30 * 2 - 1 then
  234.     abort()
  235.     end if
  236. end procedure
  237.  
  238. type natural(integer x)
  239.     return x >= 0
  240. end type
  241.  
  242. procedure atomic_ops()
  243. -- test operations on atoms
  244.     object a, x, z
  245.     integer n, m
  246.     natural p
  247.  
  248.     p = 0
  249.     p = 0.000
  250.     p = 4.0/2.0
  251.     if p != 2.0 then
  252.     abort()
  253.     end if    
  254.     n = 1
  255.     m = 1
  256.     if n and m then
  257.     else
  258.     abort()  
  259.     end if
  260.  
  261.     x = 100
  262.     sub() -- y = 200
  263.     z = 300
  264.  
  265.     if x + y != z then
  266.     abort()
  267.     end if
  268.  
  269.     if x != 100 then
  270.     abort()
  271.     end if
  272.  
  273.     if 3 * 3 != 9 or
  274.        3 * 900000000 != 2700000000 or
  275.        15000 * 32000 != 480000000 or
  276.        32000 * 15000 != 480000000 or
  277.        1000 * 13000 != 13000000 or
  278.        13000 * 1000 != 13000000 then
  279.     abort()
  280.     end if
  281.     while x != 100 do
  282.     abort()
  283.     end while
  284.  
  285.     if not (z - y = 100) then
  286.     abort()
  287.     end if
  288.  
  289.     if #FFFFFFFF != 4294967295 then
  290.     abort()
  291.     end if
  292.    
  293.     p = 20
  294.     while not (p < 10) do
  295.     p = p - 2       
  296.     end while
  297.     if p != 8 then
  298.     abort()
  299.     end if
  300.  
  301.     if x * 1000.5 != 100050 or x * y != 20000 or x / y != 0.5 then
  302.     abort()
  303.     end if
  304.  
  305.     if y < x then
  306.     abort()
  307.     end if
  308.  
  309.     if y <= x then
  310.     abort()
  311.     end if
  312.  
  313.     if x > y then
  314.     abort()
  315.     end if
  316.  
  317.     if x >= y then
  318.     abort()
  319.     end if
  320.  
  321.     if -x != -100 then
  322.     abort()
  323.     end if
  324.  
  325.     if x = x and y > z then
  326.     abort()
  327.     end if
  328.  
  329.     x = 0
  330.  
  331.     y = {"ten", "one", "two", "three", "four", "five", "six", "seven", "eight",
  332.      "nine", "ten", "ten"}
  333.  
  334.     while x <= 11 do
  335.     if x = 1 then a = "one"
  336.     elsif x = 2 then a = "two"
  337.     elsif x = 3 then a = "three"
  338.     elsif x = 4 then a = "four"
  339.     elsif x = 5 then a = "five"
  340.     elsif x = 6 then a = "six"
  341.     elsif x = 7 then a = "seven"
  342.              if 1 + 1 = 2 then
  343.                  same(a, "seven")
  344.              elsif 1 + 1 = 3 then
  345.                  abort()
  346.              else
  347.                  abort()
  348.              end if
  349.     elsif x = 8 then a = "eight"
  350.     elsif x = 9 then a = "nine"
  351.     else a = "ten"
  352.     end if
  353.     same(a, y[1+x])
  354.     x = x + 1
  355.     end while
  356.  
  357.     y = 0
  358.     for xx = 100 to 0 by -2 do
  359.     y = y + xx
  360.     end for
  361.     same(y, 50 * 51)
  362.  
  363.     for xx = 1 to 10 do
  364.     if xx = 6 then
  365.         x = 6
  366.         exit
  367.     end if
  368.     y = 1
  369.     while y < 25 do
  370.         y = y + 1
  371.         if y = 18 then
  372.         exit
  373.         end if
  374.     end while
  375.     same(y, 18)
  376.     end for
  377.     y = repeat(-99, 7)
  378.     for xx = +3 to -3 by -1 do
  379.     y[xx+4] = xx
  380.     end for
  381.     same(y, {-3, -2, -1, 0, +1, +2, +3})
  382.  
  383.     y = {1,2,3}
  384.     for xx = 1.5 to +3.0 by .5 do
  385.       y[xx] = xx
  386.     end for
  387.     same(y, {1.5, 2.5, 3.0})
  388.     y = {}
  389.     for xx = -9.0 to -9.5 by -.25 do
  390.       y = y & xx
  391.     end for
  392.     same(y, {-9, -9.25, -9.5})
  393.     y = {}
  394.     for i = 800000000 to 900000000 by 800000000 do
  395.     y = append(y, i)        
  396.     end for
  397.     if compare(y, {800000000}) then
  398.     abort()
  399.     end if
  400.     y = 5
  401.     n = 3
  402.     a = 2
  403.     for i = 1 to y by a do
  404.     n = n - 1
  405.     y = 155
  406.     a = 1
  407.     end for
  408.     same(n, 0)
  409. end procedure
  410.  
  411. procedure floating_pt()
  412. -- test floating-point operations
  413.     sequence x
  414.     atom final
  415.  
  416.     x = {1.5, -3.5, 1e10, -1e20, 0.0, 0.0001}
  417.     y = repeat(x, 10)
  418.     if x[1]/x[2] > -0.42 or x[1]/x[2] < -0.43 then
  419.     abort()
  420.     end if
  421.     if find(1e10, x) != 3 then
  422.     abort()
  423.     end if
  424.     for a = -1.0 to sqrt(999) by 2.5 do
  425.     if a > 20.0 then
  426.         final = a
  427.         exit
  428.     end if
  429.     end for
  430.     if final < 20.0 or final > 23 then
  431.     abort()
  432.     end if
  433. end procedure
  434.  
  435. function one()
  436.     return 1
  437. end function
  438.  
  439. function two()
  440.     return 2.000
  441. end function
  442.  
  443. function sequence_ops()
  444. -- test operations on sequences
  445.     object i, w, x, y, z
  446.     sequence s
  447.     integer j
  448.  
  449.     x = "Hello "
  450.     y = "World"
  451.  
  452.     if find(0, x = x) then
  453.     abort()
  454.     end if
  455.     if x[two()*two() - two()] != 'e' then
  456.     abort()
  457.     end if
  458.     if x[one()+one()] != x[two()] then
  459.     abort()
  460.     end if
  461.  
  462.     j = x[1]
  463.     if j != 'H' then
  464.     abort()
  465.     end if
  466.     s = {3.0}
  467.     s[1] = 1.0000
  468.     j = s[1]
  469.     if j != 1 then
  470.     abort()
  471.     end if
  472.     i = 1
  473.     if not atom(i) or not integer(i) then 
  474.     abort()
  475.     end if
  476.     if length(y) != 5 then 
  477.     abort()
  478.     end if
  479.     while i <= 5 do
  480.     x = append(x, y[i])
  481.     i = i + 1
  482.     end while
  483.     i = 1
  484.     while i <= 3 do
  485.     x = append(x, '.')
  486.     x = append(x, '\'')
  487.     i = i + 1
  488.     end while
  489.     same(x, "Hello World.'.'.'")
  490.     x = repeat(5, 19)
  491.     x = append(x, 20)
  492.     x[7] = 9
  493.     y = {9, 9, {9}}
  494.     y = prepend(y, 8)
  495.     y = prepend(y, {9, 9})
  496.     same(y, {{9, 9}, 8, 9, 9, {9}})
  497.     y = x
  498.     z = y * x + x + 1000
  499.     w = z > 1030 or x = 9
  500.     same(z, {1030, 1030, 1030, 1030, 1030, 1030, 1090, 1030, 1030, 1030,
  501.          1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1420})
  502.     same(w, {0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  503.          0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
  504.     x = {100, 200, {1, 2, {0, 0, 0}}, 300}
  505.     x[3][3][3] = 25
  506.     x = x * x
  507.     same(x, {10000, 40000, {1, 4, {0, 0, 625}}, 90000})
  508.     y = x / {1, 2, 3, 4}
  509.     same(y, {10000, 20000, {1/3, 4/3, {0, 0, 625/3}}, 22500})
  510.     -- & tests
  511.  
  512.     same(2 & {5, 6,7}, {2, 5, 6, 7})
  513.     same({} & 3, {3})
  514.     same("ABC" & "DEF" & "GHIJ" & {}, "ABCDEFGHIJ")
  515.     same('A' & 'B' & 'C', "ABC")
  516.  
  517.     -- slice tests
  518.     x = "ABCDEFGHIJKLMNOP"
  519.     same(x[1..4], "ABCD")
  520.     y = x[2..5]
  521.     same(y, "BCDE")
  522.     same(x[4..3], {})
  523.     same(x[4..4], "D")
  524.     x[3..5] = "000"
  525.     same(x, "AB000FGHIJKLMNOP")
  526.     x[6..9] = '8'
  527.     same(x, "AB0008888JKLMNOP")
  528.  
  529.     same(floor({1, 2, -3, 4, -5} / 3), {0, 0, -1, 1, -2})
  530.  
  531.     return y
  532. end function
  533.  
  534.  
  535. procedure sequence_ops2()
  536. -- more tests of sequence operations
  537. object x, y
  538.  
  539.     x = "ABCDEFGHIJKLMNOP"
  540.     if find('D', x) != 4 then
  541.     abort()
  542.     end if
  543.     if match("EFGH", x) != 5 then
  544.     abort()
  545.     end if
  546.     if match({"AB", "CD"}, {0, 1, 3, {}, {"AB", "C"}, "AB", "CD", "EF"}) != 6 then
  547.     abort()
  548.     end if
  549.     if compare(x,x) != 0 then
  550.     abort()
  551.     end if
  552.     if compare({}, {}) != 0 then
  553.     abort()
  554.     end if
  555.     y = repeat(repeat(repeat(99, 5), 5), 5)
  556.     if y[3][3][3] != 99 then
  557.     abort()
  558.     end if
  559.     if compare(y[4][4][3..5], repeat(99, 3)) != 0 then
  560.     abort()
  561.     end if
  562.     y[3][2][1..4] = 88
  563.     if compare(y[3][2], {88, 88, 88, 88, 99}) != 0 then
  564.     abort()
  565.     end if
  566. end procedure
  567.  
  568. procedure circularity()
  569. -- test for circular references in internal garbage collector
  570.     object x, y
  571.  
  572.     x = {{"abc", {0, 0, 0}}, "def", 1, 2}
  573.     x[3] = x
  574.     x[1..2] = x[2..3]
  575.     x = append(x, x)
  576.     x = prepend(x, x)
  577.     if compare(x, x) != 0 then
  578.     abort()
  579.     end if
  580.     y = "ABCDE"
  581.     y[2] = repeat(y, 3)
  582.     if compare(y, y) != 0 then
  583.     abort()
  584.     end if
  585. end procedure
  586.  
  587. procedure patterns()
  588. -- test wildcard routines   
  589.     if wildcard_file("ABC*DEF.*", "XBCDEF.E") then
  590.     abort()
  591.     end if
  592.     if not wildcard_file("A?B?C?D", "a1b2C3D") then
  593.     abort()
  594.     end if
  595.     if wildcard_match("AAA", "AAa") then
  596.     abort()
  597.     end if
  598.     if not wildcard_match("??Z*Z*", "ABZ123Z123") then
  599.     abort()
  600.     end if
  601. end procedure
  602.  
  603. procedure conversions()
  604. -- test conversion of values to/from string representation   
  605.     sequence v
  606.     
  607.     v = sprintf("values are: %5d, %3d, %4.2f", {1234, -89, 6.22})
  608.     if compare(v, "values are:  1234, -89, 6.22") != 0 then
  609.     abort()
  610.     end if
  611.     v = value("{1,2,3}")
  612.     if compare(v, {GET_SUCCESS, {1,2,3}}) != 0 then
  613.     abort()
  614.     end if
  615.     for x = 1 to 100 by 3 do
  616.     v = value(sprintf("%d", x)) 
  617.     if compare(v, {GET_SUCCESS, x}) != 0 then
  618.         abort()
  619.     end if
  620.     v = value(sprintf("#%x ", x))
  621.     if compare(v, {GET_SUCCESS, x}) != 0 then
  622.         abort()
  623.     end if
  624.     end for
  625. end procedure
  626.  
  627. procedure output()
  628. -- test file output routines
  629.     integer file_no
  630.  
  631.     file_no = open("sanityio.tst", "w")
  632.     if file_no < 0 then
  633.     abort() 
  634.     end if
  635.     puts(file_no, "-- io test\n")
  636.     print(file_no, {1,2,3})
  637.     puts(file_no, '\n')
  638.     print(file_no, -99)
  639.     puts(file_no, " {11, {33, {#33}}, 4, 5 }{\t\t}\n")
  640.     puts(file_no, "{} .999 -.999 1.55e00 {11,   22 , {33, 33}, 4, 5  }\n") 
  641.     printf(file_no, "%e", 10000)
  642.     printf(file_no, " %d", -123)
  643.     printf(file_no, " %5.1f", 5+1/2)
  644.     printf(file_no, "%50s\n", {"+99 1001 {1,2,3} 1E-4 {1.002e23,-59e-5,"})
  645.     printf(file_no, "%9e}\t\t-1e-20\t   -.00001e5\n", 59e30)
  646.     puts(file_no, "\"Rob\"\"ert\" \"Craig\"  ")
  647.     puts(file_no, "\"\" \"\\n\" \"\\t\\r\"\t")
  648.     puts(file_no, "\"\\'\\\"\" 'A' '\\n' '\\\"' '\\'' '\\r'\n")
  649.     printf(file_no, "{#%x, ", 291)
  650.     puts(file_no, "\"ABC\"} {'A', 'B', '\\n'}")  
  651.     close(file_no)
  652. end procedure
  653.  
  654. procedure input()
  655. -- test file input routines
  656.     integer file_no
  657.     object line
  658.     integer char
  659.  
  660.     file_no = open("sanityio.tst", "r")
  661.     if file_no < 0 then
  662.     abort()
  663.     end if
  664.     if seek(file_no, 5) then
  665.     abort()
  666.     end if
  667.     if seek(file_no, -1) then
  668.     abort()
  669.     end if
  670.     if seek(file_no, 0) then
  671.     abort()
  672.     end if
  673.     if where(file_no) != 0 then
  674.     abort()
  675.     end if
  676.     line = gets(file_no)
  677.     if compare(line, "-- io test\n") != 0 then
  678.     abort()
  679.     end if
  680.     char = getc(file_no)
  681.     if char != '{' then
  682.     abort()
  683.     end if
  684.     close(file_no)
  685. end procedure
  686.  
  687. without type_check
  688. integer color
  689. color = 1
  690. sequence v
  691.  
  692. procedure testgr()
  693. -- test basic VGA graphics operations
  694.     sequence x
  695.     
  696.     if v[VC_XPIXELS] < 100 or v[VC_YPIXELS] < 100 then
  697.     abort()
  698.     end if
  699.     draw_line(BLUE, {{20, 100}, {600, 100}})
  700.     for i = 1 to 200 by 5 do
  701.     pixel(WHITE, {3*i, i})
  702.     if get_pixel({3*i, i}) != 7 then
  703.         abort()
  704.     end if
  705.     end for
  706.     polygon(color, 0, {{20,350}, {40, 250}, {80, 400}})
  707.     ellipse(color+5, 1, {350, 350}, {440,440})
  708.     color = color + 1
  709.     x = {}
  710.     for i = 0 to 63 do
  711.     x = x & repeat(i, 2)
  712.     end for
  713.     for p = 220 to 320 by 4 do
  714.     display_image({p,p}, repeat(x+color, 2))
  715.     end for
  716. end procedure
  717. with type_check
  718.  
  719. constant TRUE = 1, FALSE = 0
  720.  
  721. procedure testget()
  722. -- test input of Euphoria objects
  723.     object gd
  724.     object x, i
  725.     object results
  726.  
  727.     gd = open("sanityio.tst", "r")
  728.     if gd < 0 or gd > 10 then
  729.     abort()
  730.     end if
  731.     if not sequence(gets(gd)) then
  732.     abort()
  733.     end if
  734.     results = {
  735.      {0, {1,2,3}},
  736.      {0, -99},
  737.      {0, {11, {33, {#33}}, 4, 5}},
  738.      {0, {}},
  739.      {0, {}},
  740.      {0, 0.999},
  741.      {0, -0.999},
  742.      {0, 1.55},
  743.      {0, {11, 22, {33, 33}, 4, 5}},
  744.      {0, 10000},
  745.      {0, -123},
  746.      {0, 5.5},
  747.      {0, 99},
  748.      {0, 1001},
  749.      {0, {1, 2, 3}},
  750.      {0, 0.0001},
  751.      {0, {1.002e+23, -0.00059, 5.9e+31}},
  752.      {0, -1e-20},
  753.      {0, -1},
  754.      {0, "Rob"},
  755.      {0, "ert"},
  756.      {0, "Craig"},
  757.      {0, ""},
  758.      {0, "\n"},
  759.      {0, "\t\r"},
  760.      {0, "\'\""},
  761.      {0, 'A'},
  762.      {0, '\n'},
  763.      {0, '\"'},
  764.      {0, '\''},
  765.      {0, '\r'},
  766.      {0, {#123, "ABC"}},
  767.      {0, {'A', 'B', '\n'}},
  768.      {-#1, 0}
  769.     }
  770.     i = 1
  771.     while TRUE do
  772.     x = get(gd)
  773.     if x[1] = -1 then
  774.         exit
  775.     end if
  776.     same(x, results[i])
  777.     i = i + 1
  778.     end while
  779.     if compare(results[i], {-1, 0}) != 0 then
  780.     puts(2, "wrong number of get values\n")
  781.     end if
  782.     close(gd)
  783. end procedure
  784.  
  785. function fib(integer n)
  786. -- fibonacci
  787.     if n < 2 then
  788.     return n
  789.     else
  790.     return fib(n-1) + fib(n-2)
  791.     end if
  792. end function
  793.  
  794. integer rp
  795.  
  796. procedure recursive_proc()
  797. -- a recursively-called procedure
  798.     if rp > 0 then
  799.     rp = rp - 1
  800.     recursive_proc()
  801.     end if
  802. end procedure
  803.  
  804. procedure machine_level()
  805. -- quick test of machine-level routines
  806.     atom addr
  807.  
  808.     addr = allocate(100)
  809.     poke(addr, #C3) -- RET instruction
  810.     if peek(addr) != #C3 then
  811.     abort()
  812.     end if
  813.     call(addr)
  814.     free(addr)
  815.     for x = 0 to +2000000 by 99999 do
  816.     if bytes_to_int(int_to_bytes(x)) != x then
  817.         abort()
  818.     end if
  819.     end for
  820.     if bits_to_int({1,0,1,0}) != 5 then
  821.     abort()
  822.     end if
  823.     if compare(int_to_bits(17,8), {1,0,0,0,1,0,0,0}) != 0 then
  824.     abort()
  825.     end if
  826. end procedure
  827.  
  828. global type sorted(sequence x)
  829. -- return TRUE if x is in ascending order
  830.     for i = 1 to length(x)-1 do
  831.     if compare(x[i], x[i+1]) > 0 then
  832.         return FALSE
  833.     end if
  834.     end for
  835.     return TRUE
  836. end type
  837.  
  838. without profile
  839.  
  840. global procedure sanity()
  841. -- main program
  842.     sequence cmd_line
  843.     integer vga
  844.  
  845.     vga = not graphics_mode(18) 
  846.     v = video_config()
  847.     clear_screen()
  848.     position(12, 20)
  849.     if compare({12, 20}, get_position()) != 0 then
  850.     abort()
  851.     end if
  852.     puts(msg, "Euphoria SANITY TEST ... ")
  853.  
  854.     for j = 0 to 8 by 2 do
  855.     if atom(getenv("EUDIR")) then
  856.         puts(1, "\nEUDIR environment variable not set - see install.doc\n")
  857.         puts(1, "\nPress Enter to continue...\n")
  858.         the_end()
  859.     end if
  860.     cmd_line = command_line()
  861.     if length(cmd_line) < 1 or length(cmd_line) > 10 then
  862.         abort()
  863.     end if
  864.     if length(current_dir()) < 2 then
  865.         abort()
  866.     end if
  867.     if length(dir(".")) < 2 then
  868.         abort()
  869.     end if
  870.     if vga then
  871.         testgr()
  872.     end if
  873.     make_sound()
  874.     same(built_in(), 1)
  875.     atomic_ops()
  876.     overflow()
  877.     floating_pt()
  878.     if compare(sequence_ops(), "BCDE") != 0 then
  879.         puts(msg, "sequence_ops failed\n")
  880.     end if
  881.     sequence_ops2()
  882.     circularity()
  883.     output()
  884.     input()
  885.     testget()
  886.     conversions()
  887.     patterns()
  888.     system("del sanityio.tst", 2)
  889.     machine_level()
  890.     rp = 100
  891.     recursive_proc()
  892.     if rp != 0 then
  893.         puts(msg, "recursive proc failed\n")
  894.     end if
  895.     if fib(20) != 6765 then
  896.         puts(msg, "fib failed\n")
  897.     end if
  898.     if not sorted(sort(-500 + rand(repeat(1000, 1000)))) then
  899.         puts(msg, "standard sort failed\n")
  900.     end if
  901.     if not sorted(sort({"robert", "junko", "dave", "ken", "lurdes"})) then
  902.         puts(msg, "standard general sort failed\n")
  903.     end if
  904.     end for
  905.     printf(msg, "%s\n", {"PASSED (100%)\n\n  <Enter> to continue"})
  906.     for i = 1 to 200 do
  907.     sound(i*20)
  908.     all_palette(rand(repeat({63,63,63}, v[VC_NCOLORS])))
  909.     end for
  910.     sound(0)
  911.     the_end()    
  912. end procedure
  913.  
  914. integer z
  915.  
  916. -- another for-loop test
  917. z = 0
  918. for j = 1 to 10 do
  919.     z = z + j
  920. end for
  921. if z != 55 then
  922.     abort()
  923. end if
  924.  
  925. sanity()
  926.  
  927.